package com.szalay.desktopsearch;

import com.szalay.desktopsearch.indexer.Indexer;
import com.szalay.desktopsearch.search.Search;
import com.szalay.desktopsearch.ui.MainWindow;
import com.szalay.desktopsearch.ui.UI;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Command line entry point.
 */
public class DesktopSearchStartup {
    /** Logger. */
    private final static Logger logger = LoggerFactory.getLogger(DesktopSearchStartup.class);
    
    public static void main(final String[] args ) {
        final String userHome = System.getProperty("user.home");
        try {
            final Indexer indexer = new Indexer(userHome + "/desktopSearch", "* 0/5 * * * ?", "* 0/3 * * * ?");
            final Search search = new Search(indexer.getSolrServer());
            
            //open ui
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    try {
                        UI.configure();
                        new MainWindow(search, indexer);
                    }
                    catch (Exception e) {
                        logger.error(null, e);
                        JOptionPane.showMessageDialog(null, e.toString());
                    }
                }
            });   
        }
        catch (Exception e) {
            logger.error(null, e);
            JOptionPane.showMessageDialog(null, e.toString());
        }
    }
}
